//package com.neuedu.hisadmin.controller;
//
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.stereotype.Controller;
//
///**
// * <p>
// *  前端控制器
// * </p>
// *
// * @author jaun
// * @since 2025-07-05
// */
//@Controller
//@RequestMapping("/rule")
//public class RuleController {
//
//}

package com.neuedu.hisadmin.controller;

import com.neuedu.hisadmin.dto.DoctorScheduleDTO;
import com.neuedu.hisadmin.dto.Result;
import com.neuedu.hisadmin.dto.RuleDTO;
import com.neuedu.hisadmin.entity.Rule;
import com.neuedu.hisadmin.entity.Scheduling;
import com.neuedu.hisadmin.service.IRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/rule")
public class RuleController {

    private final IRuleService ruleService;

    public RuleController(IRuleService ruleService) {
        this.ruleService = ruleService;
    }
        @GetMapping("/list")
        public List<RuleDTO> getRuleList() {
            // 调用 service 层获取关联数据后的规则列表
            return ruleService.getRuleWithRelations();
        }

    // 带条件查询（参数与前端表单对齐）
    @PostMapping("/search")
    public List<RuleDTO> searchRule(@RequestBody Map<String, String> params) {
        String deptName = params.get("deptName");   // 对应前端的“所属科室”
        String doctorName = params.get("doctorName"); // 对应前端的“医生姓名”
        String ruleName = params.get("ruleName");   // 对应前端的“规则名称”

        return ruleService.getRuleWithRelationsByCondition(deptName, doctorName, ruleName);
    }

    @PostMapping("/save")
    public Result<Boolean> saveRule(@RequestBody Rule rule) {
        boolean success = ruleService.saveRule(rule); // 调用原 Service 方法
        return success ?
                Result.success(true) :
                Result.error(400, "新增规则失败");
    }
}